#!/bin/bash
# ReKep Real Camera Dependencies Installation Script

echo "============================================"
echo "ReKep Real Camera Setup"
echo "============================================"

# Check if running on Linux or Windows
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
    echo "Detected Linux system"
    # Install librealsense2
    echo "Installing librealsense2..."
    sudo apt-get update
    sudo apt-get install -y librealsense2-dkms librealsense2-utils
    sudo apt-get install -y librealsense2-dev librealsense2-dbg
    
    echo "Checking RealSense devices..."
    rs-enumerate-devices
elif [[ "$OSTYPE" == "msys" || "$OSTYPE" == "win32" ]]; then
    echo "Detected Windows system"
    echo "Please download and install Intel RealSense SDK:"
    echo "https://github.com/IntelRealSense/librealsense/releases"
    echo ""
    echo "After installation, run this script again."
    exit 0
fi

# Install Python packages
echo ""
echo "Installing Python packages..."
pip install pyrealsense2

# Optional: Install SAM for advanced segmentation
read -p "Install Segment Anything Model (SAM)? (y/n): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
    echo "Installing SAM..."
    pip install git+https://github.com/facebookresearch/segment-anything.git
    echo ""
    echo "Download SAM checkpoint:"
    echo "wget https://dl.fbaipublicfiles.com/segment_anything/sam_vit_h_4b8939.pth"
fi

# Verify installation
echo ""
echo "Verifying installation..."
python -c "import pyrealsense2 as rs; print('✓ pyrealsense2 installed successfully')" || echo "✗ pyrealsense2 installation failed"

echo ""
echo "============================================"
echo "Setup completed!"
echo "============================================"
echo ""
echo "Next steps:"
echo "1. Connect your RealSense camera"
echo "2. Run: python DIY/realsense_camera.py"
echo "3. Run: python DIY/test_with_real_camera.py"

